<template>
  <div class="continer">
    <div class="search-box">
         <a href="#" class="iconfont icon-zuojiantou back" @click="Back"></a>
      <div class="search">
          
        <i class="iconfont icon-fangdajing fdj" ></i>
        <input type="text" placeholder="尖椒肉丝" v-model="title" />
      </div>
      <a @click="Search('')" class="btn_search">搜索</a>
    </div>
    <div class="search-history">
      <div class="header">
        <h4>搜索历史</h4>
        <span class="clear" @click="Delete">清除搜索历史</span>
      </div>
      <ul class="list">
        <li @click="Search(item)" v-for="(item, index) in historyList" :key="index">
          {{ item }}
        </li>
      </ul>
    </div>

    <div class="search-hot">
      <div class="header">
        <h4>热门搜索</h4>
      </div>
      <ul class="list">
        <li @click="Search(item)" v-for="(item, index) in hotList" :key="index">
          {{ item }}
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
export default {
  created() {
    this.historyList = this.$store.state.historyList;
  },
  methods: {
    Back() {
      this.$router.go(-1);
     // this.$router.push("/");
    },
    Search(key) {
        if(key==''&&this.title=='')
        return;
        if(key!='')
        this.title=key;
      this.$store.commit("SetHistoryList", {
        content: this.title,
      });
      //     this.$router.push({
      //     name:'SearchList',
      //     params:{
      //       title:this.title
      //     }
      //   })
      this.$router.push({
        path: "/SearchList",
        query: {
          title: this.title,
        },
      });
    },
    Delete() {
      this.$store.commit("DelteHistoryList");

      this.historyList = this.$store.state.historyList;
    },
  },
  data() {
    return {
      title: "",
      historyList: [
        "鲜花",
        "山姆会员商店",
        "新鲜水果.",
        "生日鲜花",
        "香槟玫瑰",
        "酸奶",
        "牛奶",
      ],
      hotList: [
        "鲜花",
        "山姆会员商店",
        "新鲜水果.",
        "生日鲜花",
        "香槟玫瑰",
        "酸奶",
        "牛奶",
      ],
    };
  },
};
</script>
<style lang="scss" scoped>
a {
  text-decoration: none;
}

.continer {
  padding: 0 18px;
  .search-box {
    margin-top: 24px;
    display: flex;
    justify-content: space-between;
    .search {
      flex: 1;
      display: flex;
      background: #f5f5f5;
      border-radius: 16px;
      height: 32px;
      position: relative;
      .fdj {
        position: absolute;
        left: 16px;
        top: 8px;
      }
      input {
        border-radius: 16px;
        width: 100%;
        border: none;
        outline: none;
        background: #f5f5f5;
        border: none;
        margin-left: 38px;
        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: #b7b7b7;
        line-height: 16px;
      }
    }
    .back{
        font-family: PingFangSC-Regular;
      font-size: 16px;
      color: #333333;
      line-height: 32px;
      margin-right: 12px;
      font-weight: bold;
    }
    .btn_search {
      font-family: PingFangSC-Regular;
      font-size: 16px;
      color: #333333;
      line-height: 32px;
      margin-left: 12px;
    }
  }
  .search-history {
    margin-top: 24px;
    .header {
      display: flex;
      justify-content: space-between;
      h4 {
        font-family: PingFangSC-Medium;
        font-size: 16px;
        color: #333333;
        font-weight: bold;
      }
      .clear {
        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: #333333;
      }
    }
    .list {
      display: flex;
      flex-wrap: wrap;
      margin-top: 20px;
      li {
        float: left;
        margin-right: 10px;
        margin-bottom: 12px;
        background: #f5f5f5;
        border-radius: 2px;
        padding: 8px 10px;
      }
    }
  }

  .search-hot {
    margin-top: 24px;
    .header {
      h4 {
        font-family: PingFangSC-Medium;
        font-size: 16px;
        color: #333333;
        font-weight: bold;
      }
    }
    .list {
      display: flex;
      flex-wrap: wrap;
      margin-top: 20px;
      li {
        float: left;
        margin-right: 10px;
        margin-bottom: 12px;
        background: #f5f5f5;
        border-radius: 2px;
        padding: 8px 10px;
      }
    }
  }
}
</style>